const BASEURL = 'https://www.uinav.com/api/public/v1/'

const ruquest = ({
  url,
  method = 'GET',
  data = {},
  header = {},
  tip = '拼命加载中...',
  isPullDownRefresh = false
}) => {
  return new Promise((resolve, reject) => {
    if (!isPullDownRefresh) {
      uni.showLoading({
        title: tip,
        mask: false
      })
    }
       const token = uni.getStorageSync('token')
       if(token){
         header.Authorization=token
       }
    uni.request({
      url: `${BASEURL}${url}`,
      method,
      header,
      data,
      success: ({ data, statusCode, header }) => {
        resolve(data)
      },
      fail: error => {
        reject(error)
      },
      complete: () => {
        if (!isPullDownRefresh) {
          uni.hideLoading()
        }
      }
    })
  })
}

uni.$request = ruquest
